<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <title>报表代码更新</title>
</head>

<body>
  <div id="app" v-cloak>
    <!-- 报表标题 -->
    <vue2-report-header :title="'报表代码更新'"></vue2-report-header>
    <el-form :inline="true" :model="info" :rules="rules" ref="infoRef" style="padding: 10px" :label-position="'left'">
      <el-form-item label="路径:" prop="path">
        <el-input style="width: 600px;" v-model="info.path" placeholder="请输入上传路径, 多层级时路径以 / 分隔, 若为根路径请填写root" clearable>
        </el-input>
      </el-form-item>
      <el-upload style="width:500px;" action="../handler/report/FileUpload.ashx?action=upload" ref="upload" multiple
        :before-remove="beforeRemove" :file-list="fileList" :data="info" :on-success="success" :on-error="error"
        :auto-upload="false" :disabled="!isLegel">
        <el-button slot="trigger" size="small" type="primary" plain :disabled="!isLegel">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" plain @click="submitUpload"
          :disabled="!isLegel">
          上传到服务器
        </el-button>
        <span style="color:red;font-weight:bold;margin-left: 10px;">内部系统，严禁上传涉密信息</span>
      </el-upload>
    </el-form>
  </div>

  <script type="module">
    import { getParams } from '../Scripts/hooks/useCommonMethod.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        info: { date: '', path: '' },
        fileList: [],
        isLegel: true,
        rules: {
          path: [{ required: true, message: '路径不能为空', trigger: 'change' }]
        }
      },
      methods: {
        async validateUser() {
          if (!getParams("uid")) {
            this.isLegel = false
            return this.$notify.error({ title: '错误', message: '缺少必要参数' });
          }
          const { data: { data, meta, total } } = await axios.post('../handler/report/UserGrantAuthorization.ashx?action=isSuperAdmin', {
            type: 'isSuperAdmin',
            employeeid: getParams('uid')
          });

          if (total < 1) {
            this.isLegel = false;
            return this.$notify.error({ title: '错误', message: '当前用户无权使用该功能!', duration: 0 });
          }
        },
        beforeRemove(file, fileList) {
          return this.$confirm(`确定移除 ${file.name}?`);
        },
        // 上传成功后
        success(response, file, fileList) {
          if (response.status === 200) {
            this.$message.success(response.msg);
          } else {
            this.$message.error(response.msg);
          }
        },
        error(err, file, fileList) { },
        submitUpload() {
          this.$refs['infoRef'].validate((valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.$refs.upload.submit();
            }
          })
        }
      },
      mounted() {
        this.info.date = dayjs().format('YYYY-MM-DD');
        this.validateUser();
      }
    })
  </script>
</body>

</html>